package com.bw.liuyushan.zhuangao4_mvptest1.MVP.Presenter;

import com.blankj.utilcode.util.ToastUtils;
import com.bw.liuyushan.mvp_lib.Presenter.BasePresenter;
import com.bw.liuyushan.zhuangao4_mvptest1.Entity.BannerBean;
import com.bw.liuyushan.zhuangao4_mvptest1.Entity.JsonBean;
import com.bw.liuyushan.zhuangao4_mvptest1.Entity.UserBean;
import com.bw.liuyushan.zhuangao4_mvptest1.Entity.ViedoBean;
import com.bw.liuyushan.zhuangao4_mvptest1.MVP.Contrack.ICTest;

import io.reactivex.Observer;
import io.reactivex.disposables.Disposable;

/**
 * ZhuanGao4_MVPTest1
 * file name is : BaseModelTest
 * created by Ender on 2021/8/11 14:37.
 * author : Liuyushan
 * Describe:P层测试类 负责获取M层数据并传递给V层显示
 */
public class BasePresenterTest extends BasePresenter<ICTest.C_ModelTest, ICTest.C_ViewTest> {
    Disposable disposable;//RxJava内存泄露处理
    public BasePresenterTest(ICTest.C_ModelTest im, ICTest.C_ViewTest iv) {
        super(im, iv);
    }
    //P层获取传递数据方法
    public void mpDate(String url){
        im.askDate(url, new Observer<ViedoBean>() {
            @Override
            public void onSubscribe(Disposable d) {
                disposable = d;//Rxjava内存泄露处理
            }

            @Override
            public void onNext(ViedoBean viedoBean) {
                iv.ShowDate(viedoBean);
            }

            @Override
            public void onError(Throwable e) {
                ToastUtils.showShort("数据请求失败");
            }

            @Override
            public void onComplete() {

            }
        });
    }
    public void mpBanner(){
        im.askBanner(new Observer<BannerBean>() {
            @Override
            public void onSubscribe(Disposable d) {
                disposable = d;//Rxjava内存泄露处理
            }

            @Override
            public void onNext(BannerBean bannerBean) {
                iv.ShowBanner(bannerBean);
            }

            @Override
            public void onError(Throwable e) {
                ToastUtils.showShort("轮播图请求失败");
            }

            @Override
            public void onComplete() {

            }
        });
    }
    public void mpFood(String url){
        im.askFood(url, new Observer<JsonBean>() {
            @Override
            public void onSubscribe(Disposable d) {
                disposable = d;//Rxjava内存泄露处理
            }

            @Override
            public void onNext(JsonBean jsonBean) {
                iv.ShowFood(jsonBean);
            }

            @Override
            public void onError(Throwable e) {
                ToastUtils.showShort("数据请求失败");
            }

            @Override
            public void onComplete() {

            }
        });
    }
    public void mpLogin(String name, String pwd){
        im.askLogin(name, pwd, new Observer<UserBean>() {
            @Override
            public void onSubscribe(Disposable d) {
                disposable = d;//Rxjava内存泄露处理
            }

            @Override
            public void onNext(UserBean userBean) {
                iv.ShowLogin(userBean);
            }

            @Override
            public void onError(Throwable e) {
                ToastUtils.showShort("数据请求失败");
            }

            @Override
            public void onComplete() {

            }
        });
    }
    public void mpRegiest(String name, String pwd){
        im.askReg(name, pwd, new Observer<UserBean>() {
            @Override
            public void onSubscribe(Disposable d) {
                disposable = d;//Rxjava内存泄露处理
            }

            @Override
            public void onNext(UserBean userBean) {
                iv.ShowReg(userBean);
            }

            @Override
            public void onError(Throwable e) {
                ToastUtils.showShort("数据请求失败");
            }

            @Override
            public void onComplete() {

            }
        });
    }
}
